package com.tc.service.Impl;

import com.tc.entity.UserInfo;
import com.tc.repository.MockUserInfoRepository;
import com.tc.service.UserInfoSerivce;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by cai.tian on 2017/5/8.
 */
@Service
@Slf4j
public class UserInfoSerivceImpl implements UserInfoSerivce {

    static {
        System.out.println("----");
    }

    @Autowired
    private MockUserInfoRepository mockUserInfoRepository;


    @Override
    public List<UserInfo> find(UserInfo u) {
        return mockUserInfoRepository.select(u);
    }

    @Override
    public void add(UserInfo u) {
        if(u==null){
            return;
        }
        mockUserInfoRepository.insert(u);
    }

    @Override
    public void delete(Long id) {
        if(id==null||id==0){
            return;
        }
        mockUserInfoRepository.delete(id);
    }

    @Override
    public void update(UserInfo userInfo) {
        if(userInfo.getId()==0){
            return;
        }
        mockUserInfoRepository.update(userInfo);
    }

    @Override
    public List<UserInfo> sortAndFind(String filed, UserInfo userInfo) {
        if(filed==null){
            return null;
        }
        return mockUserInfoRepository.sort(filed,find(userInfo));
    }

    @Override
    public String healthCheck() {
        log.info("------健康检查成功------ "+ new Date());
        System.out.println("------健康检查成功------ "+ new Date());
        return "OK";
    }
}
